﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2015-04-21 16:10:15Z</CreationDate>
</File>
*/
#endregion

namespace Outcoder.Messaging
{
	public abstract class ValueChangingMessageBase<TValue>
	{
		public TValue OldValue { get; private set; }

		public TValue NewValue { get; private set; }

		public object Sender { get; private set; }

		/// <summary>
		/// Initializes a new instance of <c>ValueChangingMessageBase</c>
		/// </summary>
		/// <param name="sender">Commonly this is the initiator of the message. Cannot be <c>null</c>.</param>
		/// <param name="oldValue">The current value.</param>
		/// <param name="newValue">What the new value will be if not cancelled.</param>
		protected ValueChangingMessageBase(object sender, TValue oldValue, TValue newValue)
		{
			Sender = ArgumentValidator.AssertNotNull(sender, "sender");

			OldValue = oldValue;
			NewValue = newValue;
		}

		bool cancel;

		public bool Cancel
		{
			get
			{
				return cancel;
			}
			set
			{
				if (cancel)
				{
					return;
				}
				cancel = value;
			}
		}
	}

	public abstract class ValueChangingMessageBase : ValueChangingMessageBase<object>
	{
		/// <summary>
		/// Initializes a new instance of <c>ValueChangingMessageBase</c>
		/// </summary>
		/// <param name="sender">Commonly this is the initiator of the message. Cannot be <c>null</c>.</param>
		/// <param name="oldValue">The current value.</param>
		/// <param name="newValue">What the new value will be if not cancelled.</param>
		protected ValueChangingMessageBase(object sender, object oldValue, object newValue)
			: base(sender, oldValue, newValue)
		{
		}
	}
}
